﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SistemaLib.Gestores;
using SistemaLib.Entidades;
using System.Web.Services;
using System.Web.Script.Services;
using System.Web.Script.Serialization;

namespace SistemaWeb.Paginas.Listas
{
    public partial class ListaTareas : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {            

        }

        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public static JqGridJson buscarTareas()
        {
            DataSet ds = GestorTareas.ListarTareas();

            var tareas = new List<Tarea>();
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                Tarea tarea = new Tarea
                {
                    Id = Convert.ToInt32(row["id"]),
                    Descripcion = row["descripcion"].ToString(),
                    FechaCreacion = Convert.ToDateTime(row["fechaCreacion"].ToString())
                };
                tareas.Add(tarea);
            }

            JqGridJson json = new JqGridJson();

            json.CurrentPage = 1;
            json.PageCount = 1;
            json.RecordCount = 1;
            json.Items = tareas;

            return json;

            //JavaScriptSerializer ser = new JavaScriptSerializer();
            //return ser.Serialize(json);
        }
    }

    public class JqGridJson
    {
        public int PageCount{get;set;}
        public int CurrentPage{get;set;}
        public int RecordCount{get;set;}

        public List<Tarea> Items{get;set;}        
    }
}
